package xin.yangshuai.juc01.hello;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Question5
 *
 * @author shuai
 * @date 2022/2/12
 */
public class Question5 implements Runnable {

    private CountDownLatch countDownLatch;

    public Question5() {
    }

    public Question5(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " :: ");
        countDownLatch.countDown();
    }
}

class Result5 {
    public static void main(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(5);

        for (int i = 0; i < 4; i++) {
            new Thread(new Question5(countDownLatch)).start();
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + " :: over");
                countDownLatch.countDown();
            }
        },"AA").start();

        countDownLatch.await();

        System.out.println(Thread.currentThread().getName() + " :: over");
    }
}
